/**
 * 用户信息修改
 * @author shanwang
 */
orange.userinfoUpdate = {
	commonUser:'b8eea75e-5290-43ca-887c-9412b257be4d',		//普通用户的标识
	finalUser:'0f064f78-993c-43a1-a0bd-8d2b3abcd7ee',		//终审专家的标识
	oldRoles:"",
	newRoles:"",
  	oldRolesText:"",
	init:function(){	//初始化用户信息
		/*var data={'username':'cstcmc','usertype':'b8eea75e-5290-43ca-887c-9412b257be4d,0f064f78-993c-43a1-a0bd-8d2b3abcd7ee'};
		$('#userinfoUpdateForm').form('load',data);*/
		//加载表单数据
		$.ajax({
			url:'userinfo/getUserinfoMsg',
			type:'post',
			data:{
				username:orange.getUserData().username
			},
			success:function(data){
				$('#userinfoUpdateForm').form('load',data.data);
				$('#userinfo_usertype').combobox('loadData',$.appCache.get('dict_tcmct_roles'));
				$('#userinfo_update_education').combobox('loadData', $.appCache.get('dict_tcmct_education'));
				$('#userinfo_update_nation').combobox('loadData', $.appCache.get('dict_tcmct_nation'));
				$('#userinfo_update_major').combobox('loadData', $.appCache.get('dict_tcmct_major'));
				$('#userinfo_update_jobtitle').combobox('loadData', $.appCache.get('dict_tcmct_jobtitle'));
				oldRolesText = $('#userinfo_usertype').combobox('getText');
				oldRoles = $('#userinfo_usertype').combobox('getValues');
				var birthday,value = $('#userinfo_idcardno').val();
				if(value.length==15){
					birthday = "19"+value.substring(6,8) + "-" + value.substring(8, 10) + "-" + value.substring(10, 12);
				}else if(value.length==18){
					birthday = value.substring(6, 10) + "-" + value.substring(10, 12) + "-" + value.substring(12, 14);
				}
				$('#userinfo_birthdate').datebox('setValue', birthday);
			}
		});
	},
	submit: function(){		//提交
		var valid =	$('#userinfoUpdateForm').form("validate");
		if(!valid){
			$.messager.alert('提示','您还有必填项未填写！','info');
			return false;
		}else{
			$.messager.progress({
				title:'请稍候',
				msg:'正在提交，请稍候...'
			});
		}
		var userinfoData = orange.systemPage.getFormData('userinfoUpdateForm');
			userinfoData.olduserrole = oldRolesText;
			userinfoData.newuserrole = $('#userinfo_usertype').combobox('getText');
			userinfoData.oldroles = oldRoles.join(',');
			userinfoData.newroles = newRoles.join(',');
		$.ajax({
			url:'userinfo/updateUserinfoWithoutPasswordService',
			type:'post',
			data:userinfoData,
			success:function(data){
				if(data.errorMsg==null){
					$.messager.progress('close');
					$.messager.show({
						title: '提示',
						msg: '基本信息修改成功，用户类型修改后需要审核',
						position: 'bottomRight',
						shadow:false,
						timeout:2500
			    	});
				}
			}
		});
	}
};

//用户类型下拉框
$('#userinfo_usertype').combobox({   
	data: $.appCache.get('dict_tcmct_roles'),
    valueField:'id',    
    textField:'name',
    panelHeight:'auto',
    width:'42%',
    required:true,
    editable:false,
    multiple:true,
    /*formatter: function (row) {
        var opts = $(this).combobox('options');
        return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField];
    },*/
    onChange:function(newValue, oldValue){
    	newRoles = newValue;
    	var val = newValue.join(','),val1=orange.userinfoUpdate.commonUser+','+orange.userinfoUpdate.finalUser,
    		val2 = orange.userinfoUpdate.finalUser+','+orange.userinfoUpdate.commonUser;
    	if(val == orange.userinfoUpdate.commonUser){
    		$('#userinfo-default-hidden').css({'display':'none'});
    	}else{
    		$('#userinfo-default-hidden').css({'display':'block'});
    	}
    	if(val == orange.userinfoUpdate.finalUser || val==val1 || val==val2){
    		$('#special_education').html('');
			$('#userinfo_update_education').combobox('disableValidation');
    	}else{
    		$('#special_education').html('*');
			$('#userinfo_update_education').combobox('enableValidation');
    	}
    }
    
});  


//学历下拉框
$('#userinfo_update_education').combobox({  
	valueField:'code',    
	textField:'value',
	panelHeight:'auto',
	required:true,
	editable:false,
	width:168
});

//民族下拉
$('#userinfo_update_nation').combobox({  
	valueField:'code',    
	textField:'value',
	panelHeight:200,
	required:true,
	editable:false,
	width:168
});

//专业下拉框
$('#userinfo_update_major').combobox({    
	valueField:'code',    
	textField:'value',
	panelHeight:200,
	required:true,
	editable:false,
	width:168
});  

//职称下拉
$('#userinfo_update_jobtitle').combobox({    
	valueField:'code',    
	textField:'value',
	panelHeight:200,
	required:true,
	editable:false,
	width:168
});


//扩展easyui表单的验证  
$.extend($.fn.validatebox.defaults.rules, {  
   /* //验证汉字  
    CHS: {  
        validator: function (value) {  
            return /^[\u0391-\uFFE5]+$/.test(value);  
        },  
        message: '请输入汉字'  
    }, */ 
    //移动手机号码验证  
    Mobile: {//value值为文本框中的值  
        validator: function (value) {  
            var reg =  /^1[3,5,7,8]\d{9}$/ ;
            return reg.test(value);  
        },  
        message: '请输入正确的电话号码格式'  
    },  
    //邮箱码验证  
    email: {//value值为文本框中的值  
    	validator: function (value) {  
    		var reg = /^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+(\.[a-zA-Z]{2,3})+$/;  
    		return reg.test(value);  
    	},  
    	message: '请输入正确的邮箱'  
    },  

    //身份证  
    IDCARD: {  
        validator: function (value) {  
            var reg =/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;  
            return reg.test(value);  
        },  
        message: '请输入正确的身份证号码'  
    }, 
    //固定电话验证
    TELEPHONE: {  
        validator: function (value) {  
            var reg =/^((0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;  
            return reg.test(value);  
        },  
        message: '请输入正确的固定电话号码'  
    }, 
});
//初始化界面
orange.userinfoUpdate.init();


